package cz.cuni.mff.abacs.burglar.logics.objects.positions;

import cz.cuni.mff.abacs.burglar.logics.DataMap;
import cz.cuni.mff.abacs.burglar.logics.objects.BaseInterface;
import cz.cuni.mff.abacs.burglar.logics.objects.BaseObject;
import cz.cuni.mff.abacs.burglar.logics.objects.Room;


/**
 * Phone to distract a guard.
 * 
 * Not used.
 * 
 * @author abacs
 *
 */
public class Phone extends BasePosition implements Position, Active {
	
	
	/** 
	 * Changeable property. */
	protected boolean _isActive = false;
	
	
	// -------------------------------------------------------------------------
	// constructors:
	
	
	/**
	 * 
	 * 
	 * @param id
	 * @param x
	 * @param y
	 * @param room
	 * @param isRinging
	 * @param referenceMap
	 */
	public Phone(
			int id,
			int x,
			int y,
			Room room,
			boolean isRinging,
			DataMap referenceMap
	) {
		super(id, BaseObject.Type.PHONE, x, y, false, room, referenceMap);
		this._isActive = isRinging;
		
	}
	
	
	/**
	 * 
	 * 
	 * @param id
	 * @param x
	 * @param y
	 * @param roomId
	 * @param isRinging
	 * @param referenceMap
	 */
	public Phone(
			int id,
			int x,
			int y,
			int roomId,
			boolean isRinging,
			DataMap referenceMap
	) {
		super(id, BaseObject.Type.PHONE, x, y, false, roomId, referenceMap);
		this._isActive = isRinging;
	}
	
	
	/**
	 * 
	 * @param other
	 * @param referenceMap
	 */
	protected Phone(Phone other, DataMap referenceMap) {
		super(other, referenceMap);
		this._isActive = other._isActive;
	}
	
	
	// -------------------------------------------------------------------------
	
	
	@Override
	public boolean isActive() {
		return this._isActive;
	}
	
	
	@Override
	public boolean changeActiveState() {
		this._isActive = ! this._isActive;
		return this._isActive;
	}
	
	
	@Override
	public boolean activate() {
		this._isActive = true;
		return true;
	}
	
	
	@Override
	public boolean deactivate() {
		this._isActive = false;
		return true;
	}
	
	
	// ------------------------------------------------------------------------

	
	@Override
	public boolean isOperable() {
		return true;
	}
	
	
	@Override
	public boolean isTrap() {
		return false;
	}
	
	
	// -------------------------------------------------------------------------
	
	
	/**
	 * From far the agent can hear whether the phone is ringing.
	 */
	@Override
	public Position examinedFromFar() {
		return new Phone(
				this.getId(),
				this.getX(),
				this.getY(),
				this._roomId,
				this._isActive,
				null
		);
	}
	
	
	/**
	 * From near the agent can hear whether the phone is ringing.
	 */
	@Override
	public Position examinedFromNear() {
		return new Phone(
				this.getId(),
				this.getX(),
				this.getY(),
				this._roomId,
				this._isActive,
				null
		);
	}
	
	
	@Override
	public boolean matchesFromFar(Position position) {
		return	super.matches(position) &&
				this._isActive == ((Phone)position)._isActive;
	}
	
	
	@Override
	public boolean matchesFromClose(Position position) {
		return	super.matches(position) &&
				this._isActive == ((Phone)position)._isActive;
	}
	
	
	@Override
	public void copyChangeables(Position original) {
		assert(original.isTypeOf(BaseInterface.Type.PHONE));
		Phone original_ =  (Phone)original;
		this._isActive = original_._isActive;
	}
	
	
	@Override
	public Position copy(DataMap referenceMap) {
		return new Phone(this, referenceMap);
	}
	
	
}
